using BuildingBlocks.Presentation.Endpoints;
using BuildingBlocks.Presentation.Results;
using Mediator;

namespace Catalog.Api.Features.CatalogItems.DeleteCatalogItem;

internal sealed class DeleteCatalogItemEndpoint : IEndpoint
{
    public void MapEndpoint(IEndpointRouteBuilder app)
    {
        app.MapDelete(
                $"{Routes.Base}/{{id}}",
                async (string id, IMediator mediator, CancellationToken cancellationToken) =>
                {
                    var result = await mediator.Send(new DeleteCatalogItemCommand(id), cancellationToken);
                    return result.Match(Results.NoContent, ApiResponse.Problem);
                })
            .WithName("DeleteCatalogItem")
            .WithTags("Catalog")
            .RequireAuthorization();
    }
}
